﻿using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Imaging;

namespace vnCommonGUI
{
    public class CommonFunction
    {
        public static int GetSelectedIndex(ComboBox cb, object o)
        {
            for(int i=0;i<cb.Items.Count;i++)
            {
                if (o == cb.Items[i]) return i;
            }
            return -1;
        }
        public static Bitmap OpenDialogImageFile()
        {
            try
            {
                OpenFileDialog open = new OpenFileDialog();
                open.Filter = "Jpg file|*.jpg|Bitmap file|*.bmp|PNG file|*.png|All file type|*.*";
                if (open.ShowDialog() == DialogResult.OK)
                {

                    return new Bitmap(new Bitmap(open.FileName),new Size(512,512));
                }
            }
            catch
            {
               
            }
            return null;
        }
        public static void SaveDialogImageFile(Image _Img)
        {
            if (_Img == null) return;
            SaveFileDialog saveFile = new SaveFileDialog();
            saveFile.Filter = "Jpg file|*.jpg|Bitmap file|*.bmp|PNG file|*.png|All file type|*.*";
            if (saveFile.ShowDialog() == DialogResult.OK)
            {
                _Img.Save(saveFile.FileName, ImageFormat.Jpeg);
            }
        }
        public static void ShowImageDetail(Image Img)
        {
            if (Img != null)
            {
                frmImageDetail fimg = new frmImageDetail(Img);
                fimg.ShowDialog();
            }
        }
    }
}
